﻿#ifndef PST_DATAMODELPOST_H
#define PST_DATAMODELPOST_H

#include <QObject>
#include <QColor>
#include <QPair>
#include <QList>
#include <tuple>
#include <QDomElement>
#include <QDomDocument>
#include <QDomAttr>
#include <iostream>
#include "BaseModule/GlobalHelper.h"

namespace pst
{
    /// @brief 轴显示
    class Style2D_Axis : public QObject
    {
        Q_OBJECT

    public:
        Q_INVOKABLE Style2D_Axis(QObject* parent = nullptr)
        //    : m_isAutoName(true), m_titleFontSize(0), m_axisThickness(0), m_valuePrecision(0), m_axisDigitSize(0) 
            :QObject(parent)
        {
        };
        ~Style2D_Axis() {};

        void copyData(const Style2D_Axis* data)
        {
            if (this == data || data == nullptr)
                return;
            this->m_isAutoName = data->m_isAutoName;
            this->m_titleText = data->m_titleText;
            this->m_xUnitType = data->m_xUnitType;
            this->m_xAxisUnit = data->m_xAxisUnit;
            this->m_yAxisUnitList = data->m_yAxisUnitList;
            this->m_titleFontColor = data->m_titleFontColor;
            this->m_titleFontSize = data->m_titleFontSize;
            this->m_axisColor = data->m_axisColor;
            this->m_axisThickness = data->m_axisThickness;
            this->m_valuePrecision = data->m_valuePrecision;
            this->m_axisDigitColor = data->m_axisDigitColor;
            this->m_axisDigitSize = data->m_axisDigitSize;
        }
        QDomElement& writeToProjectFile(QDomDocument* doc, QDomElement* element, bool isdiso)
        {
            QDomElement _Style2D_AxisRoot = doc->createElement("Style2D_Axis");

            GlobalHelperInstance->createDomElement(doc, &_Style2D_AxisRoot, "IsAutoName", QString::number(m_isAutoName));
            GlobalHelperInstance->createDomElement(doc, &_Style2D_AxisRoot, "TitleText", m_titleText);
            GlobalHelperInstance->createDomElement(doc, &_Style2D_AxisRoot, "XUnitType", QString::number(m_xUnitType));
            GlobalHelperInstance->createDomElement(doc, &_Style2D_AxisRoot, "XAxisUnit", m_xAxisUnit);
            auto _yAxisUnitListStr = GlobalHelperInstance->convertQListTupleToIntIntQStringToQString(m_yAxisUnitList);
            GlobalHelperInstance->createDomElement(doc, &_Style2D_AxisRoot, "YAxisUnitList", _yAxisUnitListStr);
            QString _titleFontColorstr = QString("%1,%2,%3").arg(m_titleFontColor.red()).arg(m_titleFontColor.green()).arg(m_titleFontColor.blue());
            GlobalHelperInstance->createDomElement(doc, &_Style2D_AxisRoot, "TitleFontColor", _titleFontColorstr);
            GlobalHelperInstance->createDomElement(doc, &_Style2D_AxisRoot, "TitleFontSize", QString::number(m_titleFontSize));
            QString _axisColorstr = QString("%1,%2,%3").arg(m_axisColor.red()).arg(m_axisColor.green()).arg(m_axisColor.blue());
            GlobalHelperInstance->createDomElement(doc, &_Style2D_AxisRoot, "AxisColor", _axisColorstr);
            GlobalHelperInstance->createDomElement(doc, &_Style2D_AxisRoot, "AxisThickness", QString::number(m_axisThickness));
            GlobalHelperInstance->createDomElement(doc, &_Style2D_AxisRoot, "ValuePrecision", QString::number(m_valuePrecision));
            QString _axisDigitColorstr = QString("%1,%2,%3").arg(m_axisDigitColor.red()).arg(m_axisDigitColor.green()).arg(m_axisDigitColor.blue());
            GlobalHelperInstance->createDomElement(doc, &_Style2D_AxisRoot, "AxisDigitColor", _axisDigitColorstr);
            GlobalHelperInstance->createDomElement(doc, &_Style2D_AxisRoot, "AxisDigitSize", QString::number(m_axisDigitSize));

            element->appendChild(_Style2D_AxisRoot);

            return _Style2D_AxisRoot;
        }

        void readFromProjectFile(QDomElement* element, bool isdiso)
        {
            auto _isAutoNameNodeList = element->elementsByTagName("IsAutoName");
            m_isAutoName = (bool)_isAutoNameNodeList.item(0).toElement().text().toInt();
            auto _TitleTextNodeList = element->elementsByTagName("TitleText");
            m_titleText = _TitleTextNodeList.item(0).toElement().text();
            auto _XUnitTypeNodeList = element->elementsByTagName("XUnitType");
            m_xUnitType = _XUnitTypeNodeList.item(0).toElement().text().toInt();
            auto _XAxisUnitNodeList = element->elementsByTagName("XAxisUnit");
            m_xAxisUnit = _XAxisUnitNodeList.item(0).toElement().text();
            auto _YAxisUnitListNodeList = element->elementsByTagName("YAxisUnitList");
            auto _yAxisUnitListStr = _YAxisUnitListNodeList.item(0).toElement().text();
            m_yAxisUnitList = GlobalHelperInstance->convertQStringToQListTupleToIntIntQString(_yAxisUnitListStr);
            auto _TitleFontColorNodeList = element->elementsByTagName("TitleFontColor");
            auto _TitleFontColorStr = _TitleFontColorNodeList.item(0).toElement().text();
            auto _TitleFontColorRGB = _TitleFontColorStr.split(",");
            m_titleFontColor.setRgb(_TitleFontColorRGB.at(0).toDouble(), _TitleFontColorRGB.at(1).toDouble(), _TitleFontColorRGB.at(2).toDouble());
            auto _TitleFontSizeNodeList = element->elementsByTagName("TitleFontSize");
            m_titleFontSize = _TitleFontSizeNodeList.item(0).toElement().text().toInt();            
            auto _axisColorNodeList = element->elementsByTagName("AxisColor");
            auto _axisColorNodeStr = _axisColorNodeList.item(0).toElement().text();
            QStringList _axisColorsl = _axisColorNodeStr.split(",");
            if (_axisColorsl.size() != 3)
                return;
            m_axisColor.setRgb(_axisColorsl.at(0).toDouble(), _axisColorsl.at(1).toDouble(), _axisColorsl.at(2).toDouble());
            auto _AxisThicknessNodeList = element->elementsByTagName("AxisThickness");
            m_axisThickness = _AxisThicknessNodeList.item(0).toElement().text().toDouble();    
            auto _ValuePrecisionNodeList = element->elementsByTagName("ValuePrecision");
            m_valuePrecision = _ValuePrecisionNodeList.item(0).toElement().text().toInt();    
            auto _AxisDigitColorNodeList = element->elementsByTagName("AxisDigitColor");
            auto _AxisDigitColorStr = _AxisDigitColorNodeList.item(0).toElement().text();
            auto _AxisDigitColorRGB = _AxisDigitColorStr.split(",");
            m_axisDigitColor.setRgb(_AxisDigitColorRGB.at(0).toDouble(), _AxisDigitColorRGB.at(1).toDouble(), _AxisDigitColorRGB.at(2).toDouble());
            auto _AxisDigitSizeNodeList = element->elementsByTagName("AxisDigitSize");
            m_axisDigitSize = _AxisDigitSizeNodeList.item(0).toElement().text().toInt();   

        }

        bool m_isAutoName{ true };       // 自动标题文本
        QString m_titleText{ "x 轴" };     // 标题文本
        int m_xUnitType{-1};          // 单位类型
        QString m_xAxisUnit{""};          // 单位
        //QList<QPair<int, QString>> m_yAxisUnitList{};//存储多个结果类型的当前单位
        QList<std::tuple<int, int, QString>> m_yAxisUnitList{};//存储多个结果类型的当前单位，存储 <文件类型，该列是实部虚部幅度相位还是标量，单位>

        QColor m_titleFontColor{ Qt::black }; // 标题字体颜色
        int m_titleFontSize{ 20 };     // 标题字体大小
        QColor m_axisColor{ Qt::black };      // 轴线颜色
        double m_axisThickness{ 1. };  // 轴线粗细
        int m_valuePrecision{ 6 }; // 数值精度
        QColor m_axisDigitColor{ Qt::black }; // 轴数字颜色
        int m_axisDigitSize{ 16 };     // 轴数字大小
    };

    /// @brief X/Y轴范围
    class Style2D_AxisRange : public QObject
    {
        Q_OBJECT

    public:
        Q_INVOKABLE Style2D_AxisRange(QObject* parent = nullptr)
            //: m_isAutoRange(false), m_maxValue(0), m_minValue(0), m_isAutoStepSize(false), m_customStepSize(0), m_isAutoScale(false), m_mainScaleValue(0), m_secondaryScaleValue(0)
            :QObject(parent)
        {
            };
        ~Style2D_AxisRange() {};

        void copyData(const Style2D_AxisRange* data)
        {
            if (this == data || data == nullptr)
                return;
            this->m_isAutoRange = data->m_isAutoRange;
            this->m_maxValue = data->m_maxValue;
            this->m_minValue = data->m_minValue;
            this->m_isAutoStepSize = data->m_isAutoStepSize;
            this->m_customStepSize = data->m_customStepSize;
            this->m_isAutoScale = data->m_isAutoScale;
            this->m_mainScaleValue = data->m_mainScaleValue;
            this->m_secondaryScaleValue = data->m_secondaryScaleValue;
        }
        QDomElement& writeToProjectFile(QDomDocument* doc, QDomElement* element, bool isdiso)
        {
            QDomElement _Style2D_AxisRangeRoot = doc->createElement("Style2D_AxisRange");

            GlobalHelperInstance->createDomElement(doc, &_Style2D_AxisRangeRoot, "IsAutoRange", QString::number(m_isAutoRange));
            GlobalHelperInstance->createDomElement(doc, &_Style2D_AxisRangeRoot, "MaxValue", QString::number(m_maxValue));
            GlobalHelperInstance->createDomElement(doc, &_Style2D_AxisRangeRoot, "MinValue", QString::number(m_minValue));
            GlobalHelperInstance->createDomElement(doc, &_Style2D_AxisRangeRoot, "IsAutoStepSize", QString::number(m_isAutoStepSize));
            GlobalHelperInstance->createDomElement(doc, &_Style2D_AxisRangeRoot, "CustomStepSize", QString::number(m_customStepSize));
            GlobalHelperInstance->createDomElement(doc, &_Style2D_AxisRangeRoot, "IsAutoScale", QString::number(m_isAutoScale));
            GlobalHelperInstance->createDomElement(doc, &_Style2D_AxisRangeRoot, "MainScaleValue", QString::number(m_mainScaleValue));
            GlobalHelperInstance->createDomElement(doc, &_Style2D_AxisRangeRoot, "SecondaryScaleValue", QString::number(m_secondaryScaleValue));

            element->appendChild(_Style2D_AxisRangeRoot);

            return _Style2D_AxisRangeRoot;
        }

        void readFromProjectFile(QDomElement* element, bool isdiso)
        {
            auto _IsAutoRangeNodeList = element->elementsByTagName("IsAutoRange");
            m_isAutoRange = (bool)_IsAutoRangeNodeList.item(0).toElement().text().toInt();
            auto _MaxValueNodeList = element->elementsByTagName("MaxValue");
            m_maxValue = _MaxValueNodeList.item(0).toElement().text().toDouble();
            auto _MinValueNodeList = element->elementsByTagName("MinValue");
            m_minValue = _MinValueNodeList.item(0).toElement().text().toDouble();
            auto _IsAutoStepSizeNodeList = element->elementsByTagName("IsAutoStepSize");
            m_isAutoStepSize = (bool)_IsAutoStepSizeNodeList.item(0).toElement().text().toInt();
            auto _CustomStepSizeNodeList = element->elementsByTagName("CustomStepSize");
            m_customStepSize = _CustomStepSizeNodeList.item(0).toElement().text().toDouble();
            auto _IsAutoScaleNodeList = element->elementsByTagName("IsAutoScale");
            m_isAutoScale = (bool)_IsAutoScaleNodeList.item(0).toElement().text().toInt();
            auto _MainScaleValueNodeList = element->elementsByTagName("MainScaleValue");
            m_mainScaleValue = _MainScaleValueNodeList.item(0).toElement().text().toDouble();
            auto _SecondaryScaleValueNodeList = element->elementsByTagName("SecondaryScaleValue");
            m_secondaryScaleValue = _SecondaryScaleValueNodeList.item(0).toElement().text().toDouble();
        }

        bool m_isAutoRange{ true };           // 是否自动范围
        double m_maxValue{ 8 };            // 最大值
        double m_minValue{ -8 };            // 最小值
        bool m_isAutoStepSize{ true };        // 是否自动步长
        double m_customStepSize{ 0 };      // 自定义步长
        bool m_isAutoScale{false};           // 是否自动刻度
        double m_mainScaleValue{0};      // 主刻度值
        double m_secondaryScaleValue{0}; // 次刻度值
    };

    /// @brief 网格线
    class Style2D_GridLine : public QObject
    {
        Q_OBJECT

    public:
        Q_INVOKABLE Style2D_GridLine(QObject* parent = nullptr)
            //: m_isMainGridLineDisplay(false), m_mainGridLineThickness(0), m_isSecondaryGridLineDisplay(false), m_secondaryGridLineThickness(0) 
            :QObject(parent)
        {
            };
        ~Style2D_GridLine() {};

        void copyData(const Style2D_GridLine* data)
        {
            if (this == data || data == nullptr)
                return;
            this->m_isMainGridLineDisplay = data->m_isMainGridLineDisplay;
            this->m_mainGridLineColor = data->m_mainGridLineColor;
            this->m_mainGridLineStyle = data->m_mainGridLineStyle;
            this->m_mainGridLineThickness = data->m_mainGridLineThickness;
            this->m_isSecondaryGridLineDisplay = data->m_isSecondaryGridLineDisplay;
            this->m_secondaryGridLineColor = data->m_secondaryGridLineColor;
            this->m_secondaryGridLineStyle = data->m_secondaryGridLineStyle;
            this->m_secondaryGridLineThickness = data->m_secondaryGridLineThickness;
        }
        QDomElement& writeToProjectFile(QDomDocument* doc, QDomElement* element, bool isdiso)
        {
            QDomElement _Style2D_GridLineRoot = doc->createElement("Style2D_GridLine");

            GlobalHelperInstance->createDomElement(doc, &_Style2D_GridLineRoot, "IsMainGridLineDisplay", QString::number(m_isMainGridLineDisplay));
            QString _mainGridLineColorstr = QString("%1,%2,%3").arg(m_mainGridLineColor.red()).arg(m_mainGridLineColor.green()).arg(m_mainGridLineColor.blue());
            GlobalHelperInstance->createDomElement(doc, &_Style2D_GridLineRoot, "MainGridLineColor", _mainGridLineColorstr);
            GlobalHelperInstance->createDomElement(doc, &_Style2D_GridLineRoot, "MainGridLineStyle", QString::number(m_mainGridLineStyle));
            GlobalHelperInstance->createDomElement(doc, &_Style2D_GridLineRoot, "MainGridLineThickness", QString::number(m_mainGridLineThickness));
            GlobalHelperInstance->createDomElement(doc, &_Style2D_GridLineRoot, "IsSecondaryGridLineDisplay", QString::number(m_isSecondaryGridLineDisplay));
            QString _secondaryGridLineColorstr = QString("%1,%2,%3").arg(m_secondaryGridLineColor.red()).arg(m_secondaryGridLineColor.green()).arg(m_secondaryGridLineColor.blue());
            GlobalHelperInstance->createDomElement(doc, &_Style2D_GridLineRoot, "SecondaryGridLineColor", _secondaryGridLineColorstr);
            GlobalHelperInstance->createDomElement(doc, &_Style2D_GridLineRoot, "SecondaryGridLineStyle", QString::number(m_secondaryGridLineStyle));
            GlobalHelperInstance->createDomElement(doc, &_Style2D_GridLineRoot, "SecondaryGridLineThickness", QString::number(m_secondaryGridLineThickness));

            element->appendChild(_Style2D_GridLineRoot);

            return _Style2D_GridLineRoot;
        }

        void readFromProjectFile(QDomElement* element, bool isdiso)
        {
            auto _IsMainGridLineDisplayNodeList = element->elementsByTagName("IsMainGridLineDisplay");
            m_isMainGridLineDisplay = (bool)_IsMainGridLineDisplayNodeList.item(0).toElement().text().toInt();

            auto _MainGridLineColorNodeList = element->elementsByTagName("MainGridLineColor");
            auto _MainGridLineColorStr = _MainGridLineColorNodeList.item(0).toElement().text();
            auto _MainGridLineColorRGB = _MainGridLineColorStr.split(",");
            m_mainGridLineColor.setRgb(_MainGridLineColorRGB.at(0).toDouble(), _MainGridLineColorRGB.at(1).toDouble(), _MainGridLineColorRGB.at(2).toDouble());

            auto _MainGridLineStyleNodeList = element->elementsByTagName("MainGridLineStyle");
            m_mainGridLineStyle = _MainGridLineStyleNodeList.item(0).toElement().text().toInt();
            auto _MainGridLineThicknessNodeList = element->elementsByTagName("MainGridLineThickness");
            m_mainGridLineThickness = _MainGridLineThicknessNodeList.item(0).toElement().text().toDouble();
            auto _IsSecondaryGridLineDisplayNodeList = element->elementsByTagName("IsSecondaryGridLineDisplay");
            m_isSecondaryGridLineDisplay = (bool)_IsSecondaryGridLineDisplayNodeList.item(0).toElement().text().toInt();

            auto _SecondaryGridLineColorNodeList = element->elementsByTagName("SecondaryGridLineColor");
            auto _SecondaryGridLineColorStr = _SecondaryGridLineColorNodeList.item(0).toElement().text();
            auto _SecondaryGridLineColorRGB = _SecondaryGridLineColorStr.split(",");
            m_secondaryGridLineColor.setRgb(_SecondaryGridLineColorRGB.at(0).toDouble(), _SecondaryGridLineColorRGB.at(1).toDouble(), _SecondaryGridLineColorRGB.at(2).toDouble());
            auto _SecondaryGridLineStyleNodeList = element->elementsByTagName("SecondaryGridLineStyle");
            m_secondaryGridLineStyle = _SecondaryGridLineStyleNodeList.item(0).toElement().text().toInt();
            auto _SecondaryGridLineThicknessNodeList = element->elementsByTagName("SecondaryGridLineThickness");
            m_secondaryGridLineThickness = _SecondaryGridLineThicknessNodeList.item(0).toElement().text().toDouble();
        }

        bool m_isMainGridLineDisplay{ true };        // 是否主网格线显示
        QColor m_mainGridLineColor{ 200,200,200 };         // 主网格线颜色
        int m_mainGridLineStyle{ 2 };             // 主网格线样式
        double m_mainGridLineThickness{ 1. };      // 主网格线粗细
        bool m_isSecondaryGridLineDisplay{ false };   // 是否次网格线显示
        QColor m_secondaryGridLineColor{ 200,200,200 };     // 次网格线颜色
        int m_secondaryGridLineStyle{ 2 };        // 次网格线样式
        double m_secondaryGridLineThickness{ 1. }; // 次网格线粗细
    };

    /// @brief 标题
    class Style2D_Title : public QObject
    {
        Q_OBJECT

    public:
        Q_INVOKABLE Style2D_Title(QObject* parent = nullptr)
            //: m_titleFontSize(0)
            :QObject(parent)
        {
            };
        ~Style2D_Title() {};

        void copyData(const Style2D_Title* data)
        {
            if (this == data || data == nullptr)
                return;
            this->m_titleName = data->m_titleName;
            this->m_titleFontColor = data->m_titleFontColor;
            this->m_titleFontSize = data->m_titleFontSize;
        }
        QDomElement& writeToProjectFile(QDomDocument* doc, QDomElement* element, bool isdiso)
        {
            QDomElement _Style2D_TitleRoot = doc->createElement("Style2D_Title");

            GlobalHelperInstance->createDomElement(doc, &_Style2D_TitleRoot, "TitleName", m_titleName);
            QString _titleFontColorstr = QString("%1,%2,%3").arg(m_titleFontColor.red()).arg(m_titleFontColor.green()).arg(m_titleFontColor.blue());
            GlobalHelperInstance->createDomElement(doc, &_Style2D_TitleRoot, "TitleFontColor", _titleFontColorstr);
            GlobalHelperInstance->createDomElement(doc, &_Style2D_TitleRoot, "TitleFontSize", QString::number(m_titleFontSize));

            element->appendChild(_Style2D_TitleRoot);

            return _Style2D_TitleRoot;
        }

        void readFromProjectFile(QDomElement* element, bool isdiso)
        {
            auto _TitleNameNodeList = element->elementsByTagName("TitleName");
            m_titleName = _TitleNameNodeList.item(0).toElement().text();

            auto _TitleFontColorNodeList = element->elementsByTagName("TitleFontColor");
            auto _TitleFontColorStr = _TitleFontColorNodeList.item(0).toElement().text();
            auto _TitleFontColorRGB = _TitleFontColorStr.split(",");
            m_titleFontColor.setRgb(_TitleFontColorRGB.at(0).toDouble(), _TitleFontColorRGB.at(1).toDouble(), _TitleFontColorRGB.at(2).toDouble());

            auto _TitleFontSizeNodeList = element->elementsByTagName("TitleFontSize");
            m_titleFontSize = _TitleFontSizeNodeList.item(0).toElement().text().toInt();
        }

        QString m_titleName{ "二维图" };     // 标题名称
        QColor m_titleFontColor{ Qt::black }; // 标题字体颜色
        int m_titleFontSize{ 20 };     // 标题字体大小
    };

    /// @brief 图例
    class Style2D_Legend : public QObject
    {
        Q_OBJECT

    public:
        Q_INVOKABLE Style2D_Legend(QObject* parent = nullptr)
            :QObject(parent)
        {
        };
        ~Style2D_Legend() {};

        void copyData(const Style2D_Legend* data)
        {
            if (this == data || data == nullptr)
                return;
            this->m_legendFontColor = data->m_legendFontColor;
            this->m_legendFontSize = data->m_legendFontSize;
            this->m_legendLineColor = data->m_legendLineColor;
            this->m_legendLineThickness = data->m_legendLineThickness;
        }
        QDomElement& writeToProjectFile(QDomDocument* doc, QDomElement* element, bool isdiso)
        {
            QDomElement _Style2D_LegendRoot = doc->createElement("Style2D_Legend");

            QString _legendFontColorstr = QString("%1,%2,%3").arg(m_legendFontColor.red()).arg(m_legendFontColor.green()).arg(m_legendFontColor.blue());
            GlobalHelperInstance->createDomElement(doc, &_Style2D_LegendRoot, "LegendFontColor", _legendFontColorstr);
            GlobalHelperInstance->createDomElement(doc, &_Style2D_LegendRoot, "LegendFontSize", QString::number(m_legendFontSize));
            QString _legendLineColorstr = QString("%1,%2,%3").arg(m_legendLineColor.red()).arg(m_legendLineColor.green()).arg(m_legendLineColor.blue());
            GlobalHelperInstance->createDomElement(doc, &_Style2D_LegendRoot, "LegendLineColor", _legendLineColorstr);
            GlobalHelperInstance->createDomElement(doc, &_Style2D_LegendRoot, "LegendLineThickness", QString::number(m_legendLineThickness));

            element->appendChild(_Style2D_LegendRoot);

            return _Style2D_LegendRoot;
        }

        void readFromProjectFile(QDomElement* element, bool isdiso)
        {
            auto _LegendFontColorNodeList = element->elementsByTagName("LegendFontColor");
            auto _LegendFontColorStr = _LegendFontColorNodeList.item(0).toElement().text();
            auto _LegendFontColorRGB = _LegendFontColorStr.split(",");
            m_legendFontColor.setRgb(_LegendFontColorRGB.at(0).toDouble(), _LegendFontColorRGB.at(1).toDouble(), _LegendFontColorRGB.at(2).toDouble());

            auto _LegendFontSizeNodeList = element->elementsByTagName("LegendFontSize");
            m_legendFontSize = _LegendFontSizeNodeList.item(0).toElement().text().toInt();

            auto _LegendLineColorNodeList = element->elementsByTagName("LegendLineColor");
            auto _LegendLineColorStr = _LegendLineColorNodeList.item(0).toElement().text();
            auto _LegendLineColorRGB = _LegendLineColorStr.split(",");
            m_legendLineColor.setRgb(_LegendLineColorRGB.at(0).toDouble(), _LegendLineColorRGB.at(1).toDouble(), _LegendLineColorRGB.at(2).toDouble());

            auto _LegendLineThicknessNodeList = element->elementsByTagName("LegendLineThickness");
            m_legendLineThickness = _LegendLineThicknessNodeList.item(0).toElement().text().toInt();
        }

        QColor m_legendFontColor{ Qt::black };     // 图例字体颜色
        int m_legendFontSize{ 16 };         // 图例字体大小
        QColor m_legendLineColor{ Qt::black };     // 图例框线颜色
        double m_legendLineThickness{ 1. }; // 图例框线粗细
    };

    /// @brief 数据属性
    class Style2D_DataProperty : public QObject
    {
        Q_OBJECT

    public:
        Q_INVOKABLE Style2D_DataProperty(QObject* parent = nullptr)
            :QObject(parent)
        {
        };
        ~Style2D_DataProperty() {};

        void copyData(const Style2D_DataProperty* data)
        {
            if (this == data || data == nullptr)
                return;
            this->m_resultDataName = data->m_resultDataName;
            this->m_dataLineColor = data->m_dataLineColor;
            this->m_dataLineStyle = data->m_dataLineStyle;
            this->m_dataLineThickness = data->m_dataLineThickness;
            this->m_isDisplaySymbol = data->m_isDisplaySymbol;
            this->m_symbolStyle = data->m_symbolStyle;
            this->m_symbolSize = data->m_symbolSize;
            this->m_symbolColor = data->m_symbolColor;
        }

        QDomElement& writeToProjectFile(QDomDocument* doc, QDomElement* element, bool isdiso)
        {
            QDomElement _Style2DDataPropertyRoot = doc->createElement("Style2D_DataProperty");

            GlobalHelperInstance->createDomElement(doc, &_Style2DDataPropertyRoot, "ResultDataName", m_resultDataName);
            QString _dataLineColorstr = QString("%1,%2,%3").arg(m_dataLineColor.red()).arg(m_dataLineColor.green()).arg(m_dataLineColor.blue());
            GlobalHelperInstance->createDomElement(doc, &_Style2DDataPropertyRoot, "DataLineColor", _dataLineColorstr);
            GlobalHelperInstance->createDomElement(doc, &_Style2DDataPropertyRoot, "DataLineStyle", QString::number(m_dataLineStyle));
            GlobalHelperInstance->createDomElement(doc, &_Style2DDataPropertyRoot, "DataLineThickness", QString::number(m_dataLineThickness));
            GlobalHelperInstance->createDomElement(doc, &_Style2DDataPropertyRoot, "IsDisplaySymbol", QString::number(m_isDisplaySymbol));
            GlobalHelperInstance->createDomElement(doc, &_Style2DDataPropertyRoot, "SymbolStyle", QString::number(m_symbolStyle));
            GlobalHelperInstance->createDomElement(doc, &_Style2DDataPropertyRoot, "SymbolSize", QString::number(m_symbolSize));
            QString _symbolColorstr = QString("%1,%2,%3").arg(m_symbolColor.red()).arg(m_symbolColor.green()).arg(m_symbolColor.blue());
            GlobalHelperInstance->createDomElement(doc, &_Style2DDataPropertyRoot, "SymbolColor", _symbolColorstr);

            element->appendChild(_Style2DDataPropertyRoot);

            return _Style2DDataPropertyRoot;
        }

        void readFromProjectFile(QDomElement* element, bool isdiso)
        {
            auto _ResultDataNameNodeList = element->elementsByTagName("ResultDataName");
            m_resultDataName = _ResultDataNameNodeList.item(0).toElement().text();

            auto _DataLineColorNodeList = element->elementsByTagName("DataLineColor");
            auto _DataLineColorStr = _DataLineColorNodeList.item(0).toElement().text();
            auto _DataLineColorRGB = _DataLineColorStr.split(",");
            m_dataLineColor.setRgb(_DataLineColorRGB.at(0).toDouble(), _DataLineColorRGB.at(1).toDouble(), _DataLineColorRGB.at(2).toDouble());

            auto _DataLineStyleNodeList = element->elementsByTagName("DataLineStyle");
            m_dataLineStyle = _DataLineStyleNodeList.item(0).toElement().text().toInt();

            auto _DataLineThicknessNodeList = element->elementsByTagName("DataLineThickness");
            m_dataLineThickness = _DataLineThicknessNodeList.item(0).toElement().text().toDouble();

            auto _IsDisplaySymbolNodeList = element->elementsByTagName("IsDisplaySymbol");
            m_isDisplaySymbol = (bool)_IsDisplaySymbolNodeList.item(0).toElement().text().toInt();

            auto _SymbolStyleNodeList = element->elementsByTagName("SymbolStyle");
            m_symbolStyle = _SymbolStyleNodeList.item(0).toElement().text().toInt();

            auto _SymbolSizeNodeList = element->elementsByTagName("SymbolSize");
            m_symbolSize = _SymbolSizeNodeList.item(0).toElement().text().toDouble();

            auto _SymbolColorNodeList = element->elementsByTagName("SymbolColor");
            auto _SymbolColorStr = _SymbolColorNodeList.item(0).toElement().text();
            auto _SymbolColorRGB = _SymbolColorStr.split(",");
            m_symbolColor.setRgb(_SymbolColorRGB.at(0).toDouble(), _SymbolColorRGB.at(1).toDouble(), _SymbolColorRGB.at(2).toDouble());
        }

        QString m_resultDataName;   // 结果数据名称
        QColor m_dataLineColor{Qt::red};     // 数据线颜色
        int m_dataLineStyle{0};        // 数据线样式
        double m_dataLineThickness{ 2. }; // 数据线粗细
        bool m_isDisplaySymbol{false};     // 是否显示符号
        int m_symbolStyle{ 0 };          // 符号样式
        double m_symbolSize{ 3 };        // 符号大小
        QColor m_symbolColor{ Qt::black };       // 符号颜色
    };

    /// @brief 颜色条
    class Style2D_ColorBar : public QObject
    {
        Q_OBJECT

    public:
        Q_INVOKABLE Style2D_ColorBar(QObject* parent = nullptr)
            //: m_isAutoRange(false), m_maxValue(0), m_minValue(0), m_fontSize(0) {
            :QObject(parent)
        {
        };
        ~Style2D_ColorBar() {};

        void copyData(const Style2D_ColorBar* data)
        {
            if (this == data || data == nullptr)
                return;
            this->m_isAutoRange = data->m_isAutoRange;
            this->m_maxValue = data->m_maxValue;
            this->m_minValue = data->m_minValue;
            this->m_fontColor = data->m_fontColor;
            this->m_fontSize = data->m_fontSize;
        }
        QDomElement& writeToProjectFile(QDomDocument* doc, QDomElement* element, bool isdiso)
        {
            QDomElement _Style2D_ColorBarRoot = doc->createElement("Style2D_ColorBar");

            GlobalHelperInstance->createDomElement(doc, &_Style2D_ColorBarRoot, "IsAutoRange", QString::number(m_isAutoRange));
            GlobalHelperInstance->createDomElement(doc, &_Style2D_ColorBarRoot, "MaxValue", QString::number(m_maxValue));
            GlobalHelperInstance->createDomElement(doc, &_Style2D_ColorBarRoot, "MinValue", QString::number(m_minValue));
            QString _fontColorstr = QString("%1,%2,%3").arg(m_fontColor.red()).arg(m_fontColor.green()).arg(m_fontColor.blue());
            GlobalHelperInstance->createDomElement(doc, &_Style2D_ColorBarRoot, "FontColor", _fontColorstr);
            GlobalHelperInstance->createDomElement(doc, &_Style2D_ColorBarRoot, "FontSize", QString::number(m_fontSize));

            element->appendChild(_Style2D_ColorBarRoot);

            return _Style2D_ColorBarRoot;
        }

        void readFromProjectFile(QDomElement* element, bool isdiso)
        {
            auto _IsAutoRangeNodeList = element->elementsByTagName("IsAutoRange");
            m_isAutoRange = (bool)_IsAutoRangeNodeList.item(0).toElement().text().toInt();

            auto _MaxValueNodeList = element->elementsByTagName("MaxValue");
            m_maxValue = _MaxValueNodeList.item(0).toElement().text().toDouble();

            auto _MinValueNodeList = element->elementsByTagName("MinValue");
            m_minValue = _MinValueNodeList.item(0).toElement().text().toDouble();

            auto _FontColorNodeList = element->elementsByTagName("FontColor");
            auto _FontColorStr = _FontColorNodeList.item(0).toElement().text();
            auto _FontColorRGB = _FontColorStr.split(",");
            m_fontColor.setRgb(_FontColorRGB.at(0).toDouble(), _FontColorRGB.at(1).toDouble(), _FontColorRGB.at(2).toDouble());

            auto _FontSizeNodeList = element->elementsByTagName("FontSize");
            m_fontSize = _FontSizeNodeList.item(0).toElement().text().toInt();
        }

        bool m_isAutoRange{true}; // 是否自动范围
        double m_maxValue{1.};  // 最大值
        double m_minValue{0.};  // 最小值
        QColor m_fontColor{Qt::black}; // 字体颜色
        int m_fontSize{16};   // 字体大小
    };

    /// @brief 标记属性
    class Style2D_TracerProperty : public QObject
    {
        Q_OBJECT

    public:
        Q_INVOKABLE Style2D_TracerProperty(QObject* parent = nullptr)
            :QObject(parent)
        {
        }
        ~Style2D_TracerProperty() {};

        void copyData(const Style2D_TracerProperty* data)
        {
            if (this == data || data == nullptr)
                return;
            this->m_tracerName = data->m_tracerName;
            this->m_x = data->m_x;
            this->m_y = data->m_y;
            this->m_value = data->m_value;
            this->m_symbolStyle = data->m_symbolStyle;
            this->m_symbolSize = data->m_symbolSize;
            this->m_symbolColor = data->m_symbolColor;
        }
        QDomElement& writeToProjectFile(QDomDocument* doc, QDomElement* element, bool isdiso)
        {
            QDomElement _Style2D_TracerPropertyRoot = doc->createElement("Style2D_TracerProperty");
            GlobalHelperInstance->createDomElement(doc, &_Style2D_TracerPropertyRoot, "TracerName", m_tracerName);
            GlobalHelperInstance->createDomElement(doc, &_Style2D_TracerPropertyRoot, "TracerX", QString::number(m_x));
            GlobalHelperInstance->createDomElement(doc, &_Style2D_TracerPropertyRoot, "TracerY", QString::number(m_y));
            GlobalHelperInstance->createDomElement(doc, &_Style2D_TracerPropertyRoot, "Value", QString::number(m_value));
            GlobalHelperInstance->createDomElement(doc, &_Style2D_TracerPropertyRoot, "SymbolStyle", QString::number(m_symbolStyle));
            GlobalHelperInstance->createDomElement(doc, &_Style2D_TracerPropertyRoot, "SymbolSize", QString::number(m_symbolSize));
            QString _symbolColorstr = QString("%1,%2,%3").arg(m_symbolColor.red()).arg(m_symbolColor.green()).arg(m_symbolColor.blue());
            GlobalHelperInstance->createDomElement(doc, &_Style2D_TracerPropertyRoot, "SymbolColor", _symbolColorstr);

            element->appendChild(_Style2D_TracerPropertyRoot);

            return _Style2D_TracerPropertyRoot;
        }

        void readFromProjectFile(QDomElement* element, bool isdiso)
        {
            auto _TracerNameNodeList = element->elementsByTagName("TracerName");
            m_tracerName = _TracerNameNodeList.item(0).toElement().text();

            auto _TracerXNodeList = element->elementsByTagName("TracerX");
            m_x = _TracerXNodeList.item(0).toElement().text().toDouble();

            auto _TracerYNodeList = element->elementsByTagName("TracerY");
            m_y = _TracerYNodeList.item(0).toElement().text().toDouble();

            auto _ValueNodeList = element->elementsByTagName("Value");
            m_value = _ValueNodeList.item(0).toElement().text().toDouble();

            auto _SymbolStyleNodeList = element->elementsByTagName("SymbolStyle");
            m_symbolStyle = _SymbolStyleNodeList.item(0).toElement().text().toInt();

            auto _SymbolSizeNodeList = element->elementsByTagName("SymbolSize");
            m_symbolSize = _SymbolSizeNodeList.item(0).toElement().text().toDouble();

            auto _SymbolColorNodeList = element->elementsByTagName("SymbolColor");
            auto _SymbolColorStr = _SymbolColorNodeList.item(0).toElement().text();
            auto _SymbolColorRGB = _SymbolColorStr.split(",");
            m_symbolColor.setRgb(_SymbolColorRGB.at(0).toDouble(), _SymbolColorRGB.at(1).toDouble(), _SymbolColorRGB.at(2).toDouble());
        }

        QString m_tracerName; // 标记名称
        double m_x;           // 标记x值
        double m_y;           // 标记y值
        double m_value;       // 标记x、y对应点的值
        int m_symbolStyle{2};  // 符号样式
        double m_symbolSize{3}; // 符号大小
        QColor m_symbolColor{Qt::red}; // 符号颜色
    };

    /// @brief 参考线属性
    class Style2D_GuideLineProperty : public QObject
    {
        Q_OBJECT

    public:
        Q_INVOKABLE Style2D_GuideLineProperty(QObject* parent = nullptr)
            :QObject(parent)
        {
        }
        ~Style2D_GuideLineProperty() {};

        void copyData(const Style2D_GuideLineProperty* data)
        {
            if (this == data || data == nullptr)
                return;
            this->m_value = data->m_value;
            this->m_guideLineStyle = data->m_guideLineStyle;
            this->m_guideLineThickness = data->m_guideLineThickness;
            this->m_guideLineColor = data->m_guideLineColor;
        }
        QDomElement& writeToProjectFile(QDomDocument* doc, QDomElement* element, bool isdiso)
        {
            QDomElement _Style2D_GuideLinePropertyRoot = doc->createElement("Style2D_GuideLineProperty");
            GlobalHelperInstance->createDomElement(doc, &_Style2D_GuideLinePropertyRoot, "Value", QString::number(m_value));
            GlobalHelperInstance->createDomElement(doc, &_Style2D_GuideLinePropertyRoot, "GuideLineStyle", QString::number(m_guideLineStyle));
            GlobalHelperInstance->createDomElement(doc, &_Style2D_GuideLinePropertyRoot, "GuideLineThickness", QString::number(m_guideLineThickness));
            QString _guideLineColorstr = QString("%1,%2,%3").arg(m_guideLineColor.red()).arg(m_guideLineColor.green()).arg(m_guideLineColor.blue());
            GlobalHelperInstance->createDomElement(doc, &_Style2D_GuideLinePropertyRoot, "GuideLineColor", _guideLineColorstr);

            element->appendChild(_Style2D_GuideLinePropertyRoot);

            return _Style2D_GuideLinePropertyRoot;
        }
        

        void readFromProjectFile(QDomElement* element, bool isdiso)
        {
            auto _ValueNodeList = element->elementsByTagName("Value");
            m_value = _ValueNodeList.item(0).toElement().text().toDouble();

            auto _GuideLineStyleNodeList = element->elementsByTagName("GuideLineStyle");
            m_guideLineStyle = _GuideLineStyleNodeList.item(0).toElement().text().toInt();

            auto _GuideLineThicknessNodeList = element->elementsByTagName("GuideLineThickness");
            m_guideLineThickness = _GuideLineThicknessNodeList.item(0).toElement().text().toDouble();

            auto _GuideLineColorNodeList = element->elementsByTagName("GuideLineColor");
            auto _GuideLineColorStr = _GuideLineColorNodeList.item(0).toElement().text();
            auto _GuideLineColorRGB = _GuideLineColorStr.split(",");
            m_guideLineColor.setRgb(_GuideLineColorRGB.at(0).toDouble(), _GuideLineColorRGB.at(1).toDouble(), _GuideLineColorRGB.at(2).toDouble());
        }

        double m_value{0};            // 参考线值
        int m_guideLineStyle{2};      // 数据线样式
        double m_guideLineThickness{1}; // 数据线粗细
        QColor m_guideLineColor{Qt::black};      // 数据线颜色
    };

    struct DataTracer2DSettings
    {
        Style2D_TracerProperty* tracerProperty;
        Style2D_GuideLineProperty* guideLineProperty;
    };
} // namespace pst

#endif // PST_DATAPOLARCOORDINATE_H
